package cauca.scsn.modelo.entidad;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import cauca.scsn.modelo.entidad.id.FacturaId;

/**
 * Factura entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "factura", schema = "public")
public class Factura extends EntidadGenerica {

	// Fields

	private FacturaId id;
	private Empresa empresa;
	private Proveedor proveedor;
	private Double costo;
	private Date fecha;
	private Set<Neumatico> neumaticos = new HashSet<Neumatico>(0);

	// Constructors

	/** default constructor */
	public Factura() {
	}

	/** minimal constructor */
	public Factura(FacturaId id, Empresa empresa, Proveedor proveedor,
			Double costo, Date fecha, String status) {
		this.id = id;
		this.empresa = empresa;
		this.proveedor = proveedor;
		this.costo = costo;
		this.fecha = fecha;
		this.status = status;
	}

	/** full constructor */
	public Factura(FacturaId id, Empresa empresa, Proveedor proveedor,
			Double costo, Date fecha, String status, Set<Neumatico> neumaticos) {
		this.id = id;
		this.empresa = empresa;
		this.proveedor = proveedor;
		this.costo = costo;
		this.fecha = fecha;
		this.status = status;
		this.neumaticos = neumaticos;
	}

	// Property accessors
	@EmbeddedId
	@AttributeOverrides({
			@AttributeOverride(name = "idProveedor", column = @Column(name = "id_proveedor", nullable = false)),
			@AttributeOverride(name = "nroFactura", column = @Column(name = "nro_factura", nullable = false, length = 60)) })
	public FacturaId getId() {
		return this.id;
	}

	public void setId(FacturaId id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_empresa", nullable = false)
	public Empresa getEmpresa() {
		return this.empresa;
	}

	public void setEmpresa(Empresa empresa) {
		this.empresa = empresa;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_proveedor", nullable = false, insertable = false, updatable = false)
	public Proveedor getProveedor() {
		return this.proveedor;
	}

	public void setProveedor(Proveedor proveedor) {
		this.proveedor = proveedor;
	}

	@Column(name = "costo", nullable = false, precision = 17, scale = 17)
	public Double getCosto() {
		return this.costo;
	}

	public void setCosto(Double costo) {
		this.costo = costo;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "fecha", nullable = false, length = 13)
	public Date getFecha() {
		return this.fecha;
	}

	public void setFecha(Date fecha) {
		this.fecha = fecha;
	}

	@Column(name = "status", nullable = false, length = 1)
	public String getStatus() {
		return this.status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "factura")
	public Set<Neumatico> getNeumaticos() {
		return this.neumaticos;
	}

	public void setNeumaticos(Set<Neumatico> neumaticos) {
		this.neumaticos = neumaticos;
	}

	@Override
	public Object getPrimaryKey() {
		return this.id;
	}

	@Override
	public String toString() {
		return null;
	}

}